<template>
    <div class="member-add">
        <Tabs v-model="tabType" @on-click="getData">
            <Tab-pane label="链接设置" name="1"></Tab-pane>
            <Tab-pane label="奖金设置" name="2"></Tab-pane>
            <Tab-pane label="兑换股权设置" name="3"></Tab-pane>
            <Tab-pane label="C2C设置" name="4"></Tab-pane>
            <Tab-pane label="投资设置" name="5"></Tab-pane>
        </Tabs>


        <Form :label-width="200" style="width: 20%;">
            <FormItem :label="ice.name" v-for="(ice,index) in icecream" :key="index">
                <!--<Input v-model="ice.value" size="large" type="textarea"></Input>-->
                <Input v-model="ice.value" size="large"></Input>
            </FormItem>
            <FormItem>
                <Button type="primary" @click="changeForm">提交</Button>
                <Button type="warning" @click="openTest">测试</Button>
            </FormItem>
        </Form>
        <!--<div class="member-add-card">-->
        <!--<Row :gutter="16">-->
        <!--<Col span="12">-->
        <!--<Card>-->
        <!--<p slot="title">-->
        <!--<a><Icon type="gear-a"></Icon> 基本信息</a>-->
        <!--</p>-->
        <!--<div class="formCon">-->
        <!--<a class="title">{{title}}</a>-->
        <!--<Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">-->
        <!--<FormItem label="编号" prop="username">-->
        <!--<Input v-model="formValidate.username" placeholder="请输入账号"></Input>-->
        <!--</FormItem>-->
        <!--<FormItem label="手机号码" prop="phone">-->
        <!--<Input v-model="formValidate.phone" placeholder="请输入手机号码"></Input>-->
        <!--</FormItem>-->
        <!--<FormItem label="密码" prop="pwd">-->
        <!--<Input type="password" v-model="formValidate.pwd" placeholder="如不修改 请留空"></Input>-->
        <!--</FormItem>-->
        <!--&lt;!&ndash;<FormItem label="二级密码" prop="twopwd">-->
        <!--<Input :disabled="isEdit" type="password" v-model="formValidate.repwd" placeholder="请输入二级密码"></Input>-->
        <!--</FormItem>&ndash;&gt;-->
        <!--&lt;!&ndash;<FormItem label="用户名" prop="username">&ndash;&gt;-->
        <!--&lt;!&ndash;<Input v-model="formValidate.username" placeholder="请输入用户名"></Input>&ndash;&gt;-->
        <!--&lt;!&ndash;</FormItem>&ndash;&gt;-->
        <!--&lt;!&ndash;<FormItem label="性别" prop="sex">&ndash;&gt;-->
        <!--&lt;!&ndash;<RadioGroup v-model="formValidate.sex">&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="1">男</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="2">女</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="3">保密</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;</RadioGroup>&ndash;&gt;-->
        <!--&lt;!&ndash;</FormItem>&ndash;&gt;-->
        <!--<FormItem label="状态" prop="status">-->
        <!--<RadioGroup v-model="formValidate.status">-->
        <!--<Radio label="-2">冻结</Radio>-->
        <!--<Radio label="99">注册会员</Radio>-->
        <!--<Radio label="1">正式会员</Radio>-->
        <!--</RadioGroup>-->
        <!--</FormItem>-->
        <!--&lt;!&ndash;<FormItem label="级别" prop="level">&ndash;&gt;-->
        <!--&lt;!&ndash;<RadioGroup v-model="formValidate.level">&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="1">vip会员</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="2">金卡会员</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="3">钻石会员</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="4">红钻会员</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="5">皇钻会员</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;</RadioGroup>&ndash;&gt;-->
        <!--&lt;!&ndash;</FormItem>&ndash;&gt;-->

        <!--<FormItem label="电子邮箱" prop="email">-->
        <!--<Input v-model="formValidate.email" placeholder="请输入电子邮箱"></Input>-->
        <!--</FormItem>-->
        <!--<FormItem label="真实姓名" prop="real_name">-->
        <!--<Input v-model="formValidate.real_name" placeholder="请输入真实姓名"></Input>-->
        <!--</FormItem>-->
        <!--&lt;!&ndash;<FormItem label="生日" prop="birthday">&ndash;&gt;-->
        <!--&lt;!&ndash;<Input v-model="formValidate.birthday" placeholder="请输入生日 格式：xxxx-xx-xx"></Input>&ndash;&gt;-->
        <!--&lt;!&ndash;</FormItem>&ndash;&gt;-->
        <!--<FormItem label="推荐人" prop="tuijian_name">-->
        <!--<Input v-model="formValidate.tuijian_name" placeholder="请输入推荐人"></Input>-->
        <!--</FormItem>-->
        <!--&lt;!&ndash;<FormItem label="团呗币" prop="tuanbei">&ndash;&gt;-->
        <!--&lt;!&ndash;<Input number v-model="formValidate.tuanbei" placeholder="请输入团呗币"></Input>&ndash;&gt;-->
        <!--&lt;!&ndash;</FormItem>&ndash;&gt;-->
        <!--&lt;!&ndash;<FormItem label="推手等级" prop="dengji">&ndash;&gt;-->
        <!--&lt;!&ndash;<RadioGroup v-model="formValidate.dengji">&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="1">普通推手</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="2">金牌推手</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;</RadioGroup>&ndash;&gt;-->
        <!--&lt;!&ndash;</FormItem>&ndash;&gt;-->
        <!--&lt;!&ndash;<FormItem label="会员状态" prop="status">&ndash;&gt;-->
        <!--&lt;!&ndash;<RadioGroup v-model="formValidate.status">&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="1">启用</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;<Radio label="0">停用</Radio>&ndash;&gt;-->
        <!--&lt;!&ndash;</RadioGroup>&ndash;&gt;-->
        <!--&lt;!&ndash;</FormItem>&ndash;&gt;-->
        <!--</Form>-->
        <!--</div>-->
        <!--</Card>-->
        <!--</Col>-->
        <!--&lt;!&ndash;<Col span="12">&ndash;&gt;-->
        <!--&lt;!&ndash;<Card>&ndash;&gt;-->
        <!--&lt;!&ndash;<p slot="title">&ndash;&gt;-->
        <!--&lt;!&ndash;<a><Icon type="ios-cloud-upload-outline"></Icon> 头像上传</a>&ndash;&gt;-->
        <!--&lt;!&ndash;</p>&ndash;&gt;-->
        <!--&lt;!&ndash;<Upload accept="image/png, image/jpeg, image/gif, image/jpg" type="drag" action="?" :before-upload="handleBeforeUpload">&ndash;&gt;-->
        <!--&lt;!&ndash;<div class="upImg">&ndash;&gt;-->
        <!--&lt;!&ndash;<a><Icon type="ios-cloud-upload" size="52"></Icon></a>&ndash;&gt;-->
        <!--&lt;!&ndash;<p>点击或将图片拖拽到这里上传</p>&ndash;&gt;-->
        <!--&lt;!&ndash;</div>&ndash;&gt;-->
        <!--&lt;!&ndash;</Upload>&ndash;&gt;-->
        <!--&lt;!&ndash;</Card>&ndash;&gt;-->
        <!--&lt;!&ndash;<Card style="height: 312px;margin-top: 20px">&ndash;&gt;-->
        <!--&lt;!&ndash;<p slot="title">&ndash;&gt;-->
        <!--&lt;!&ndash;<a><Icon type="ios-person"></Icon> 头像展示</a>&ndash;&gt;-->
        <!--&lt;!&ndash;</p>&ndash;&gt;-->
        <!--&lt;!&ndash;<a slot="extra" @click="imgUrl = ''"><Icon type="close"></Icon>清除</a>&ndash;&gt;-->
        <!--&lt;!&ndash;<img class="imgUp" v-if="imgUrl!=''" :src="imgUrl"/>&ndash;&gt;-->
        <!--&lt;!&ndash;</Card>&ndash;&gt;-->
        <!--&lt;!&ndash;</Col>&ndash;&gt;-->
        <!--</Row>-->
        <!--&lt;!&ndash;提交&ndash;&gt;-->
        <!--<div class="subCon">-->
        <!--<ButtonGroup>-->
        <!--<Button type="primary" @click="sub" :loading="loading">提交</Button>-->
        <!--<Button type="ghost" @click="reset">重置</Button>-->
        <!--</ButtonGroup>-->
        <!--</div>-->
        <!--</div>-->
    </div>
</template>
<script>
    import Cookies from 'js-cookie';
    export default {
        name: "config-list",
        data() {
            const validateNum = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('请输入数字'));
                }
                // 模拟异步验证效果
                setTimeout(() => {
                    if (!Number.isInteger(value)) {
                        callback(new Error("请输入数字"));
                    } else {
                        callback();
                    }
                }, 1000);
            };
            return {
                icecream: [],
                title: "新增会员",
                formValidate: {
                    name: "",
                    pwd: "",
                    /*twopwd:"",*/
                    username: "",
                    sex: "1",
                    phone: "",
                    email: "",
                    // shangji:"",
                    // tuanbei:"",
                    // dengji:"1",
                    status: "99",
                    level: '1',
                    real_name: '',
                    birthday: '',
                    tuijian_name: ''
                },
                ruleValidate: {
                    name: [{required: true, message: '请输入账号', trigger: 'blur'}],
                    pwd: [{required: false, message: '请输入密码', trigger: 'blur'}],
                    twopwd: [{required: false, message: '请输入密码', trigger: 'blur'}],
                    username: [{required: true, message: '请输入用户名', trigger: 'blur'}],
                    sex: [{required: true, message: '请选择性别', trigger: 'change'}],
                    phone: [{required: true, message: '请输入手机号码', trigger: 'blur'}],
                    email: [{required: false, message: '请输入电子邮箱', trigger: 'blur'}],
                    tuijian_name: [{required: false, message: '请输入推荐人', trigger: 'blur'}],
                    // shangji: [{ required: true, message: '请输入上级推手', trigger: 'blur' }],
                    // tuanbei: [{ required: true, validator: validateNum, trigger: 'blur' }],
                    level: [{required: true, message: '请选择等级', trigger: 'change'}],
                    status: [{required: true, message: '请选转状态', trigger: 'change'}],
                },
                imgUrl: "",
                loading: false,
                isEdit: false,
                uid: "",
                tabType: '1'
            }
        },
        mounted() {
            // if(this.$route.query.isEdit){
            //     this.isEdit = true
            //     this.uid=this.$route.query.uid
            //     this.getData()
            //     this.title = "修改会员"
            // }
            this.getData()

        },
        methods: {
            getData() {
                this.getJsonData("Config/getAllConfig",{type: this.tabType})
                  .then((res) => {
                      if (this.tabType === '5') {
                          this.icecream = [
                              {
                                  name: '投资名称',
                                  key: 'project_name',
                                  value: '',
                              },
                              {
                                  name: '投资周期',
                                  key: 'project_cycle',
                                  value: '',
                              },
                              {
                                  name: '每次最小投资',
                                  key: 'project_min',
                                  value: '',
                              },
                              {
                                  name: '每次最大投资',
                                  key: 'project_max',
                                  value: '',
                              },
                              {
                                  name: '每日全网投资最多限制',
                                  key: 'project_max_num',
                                  value: '',
                              },
                              {
                                  name: '当前ZOL-USDT价格',
                                  key: 'trade_price',
                                  value: '',
                              },
                              {
                                  name: '当前ZOL-RMB价格',
                                  key: 'trade_rmb',
                                  value: '',
                              },
                              {
                                  name: '当前ZOL涨幅',
                                  key: 'trade_size',
                                  value: '',
                              }
                          ]
                          this.icecream.forEach(item => {
                              item.value = res.config[item.key];
                          })
                      } else {
                          this.icecream = res.config
                      }
                  })

            },
            sureSub() {
                /*if(this.imgUrl=="")
                {
                    this.$Message.warning("请上传头像");
                    return;
                }*/
                this.loading = true;
                let obj = {
                    tuijian_name: this.formValidate.tuijian_name,
                    name: this.formValidate.name,
                    pwd: this.formValidate.pwd,
                    /*twopwd:this.formValidate.twopwd,*/
                    sex: this.formValidate.sex,
                    username: this.formValidate.username,
                    phone: this.formValidate.phone,
                    pic: this.imgUrl,
                    status: this.formValidate.status,
                    email: this.formValidate.email,
                    real_name: this.formValidate.real_name,
                    level: this.formValidate.level,
                    year: this.formValidate.birthday.split("-")[0],
                    month: this.formValidate.birthday.split("-")[1],
                    day: this.formValidate.birthday.split("-")[2],
                };
                if (this.isEdit) this.$set(obj, "uid", this.uid)
                this.getJsonData("User/addUser", obj, true)
                    .then((res) => {
                        this.loading = false
                        this.$Message.success(this.isEdit ? '修改成功' : '新增成功')
                        this.$router.back()
                    })
                    .catch((res) => {
                        this.loading = false
                    })
            },
            reset() {
                this.imgUrl = ""
                this.$refs.formValidate.resetFields();
            },
            changeForm() {
                let obj={
                    token: Cookies.get("token"),
                };
                if (this.tabType === '5') obj['type'] = '5';
                this.icecream.forEach((ice,index)=>{
                    obj[ice.key]=ice.value;
                });
                this.$http.post(this.ajxaHttpUrl+'Config/changeConfig',obj).then(res=>{
                    this.$Message.success(res.data.msg);
                })
            },
            openTest() {
                window.open(this.imgHttpUrl + '/AUTO_Z/money_auto_ceshi.php')
            }
        }
    }
</script>
<style lang="less">
    @import "./config-list";
</style>
